#ifndef __TWNTNTB
#define __TWNTNTB 1

#ifdef TWNALONE_TNTB
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include "ApmsApi.h"
#include "XlsObj.h"
#include "Tianwan.h"
#include "Uti_Tianwan.h"
#define TNTBUILDER_API extern "C" __declspec(dllexport)
#else
#define TNTBUILDER_API extern "C" __declspec(dllimport)
#endif

//Define del sistema,//
#define TENORE_NT_SERVER				""

//Define specifiche per il file di Log.//
#define LOG_FILE_PATH				"D:\\TenoreNT\\Logs\\LogFile.txt"

//Define per il path del foglio Excel.//
#define EXCEL_PATH					"D:\\Tianwan\\Config\\Xls\\Tianwan_xls_conf.xls"

// Define per i numeri dei fogli Excel all'interno del file .xls" //
#define EXCEL_SHEET_GEN_DESCR		1
#define EXCEL_SHEET_ZONE_DESCR		2
#define EXCEL_SHEET_VIRT_COORD		3
#define EXCEL_SHEET_OBJT_TYPE		4
#define EXCEL_SHEET_OBJ				5
#define EXCEL_SHEET_TOOLS			6
#define EXCEL_SHEET_PATHS			7
#define EXCEL_SHEET_MICRO_OP		8
#define EXCEL_SHEET_MACRO_OP		9
#define EXCEL_SHEET_OSEQ			10
#define EXCEL_SHEET_PHAS			11
#define EXCEL_SHEET_TECC			12
#define EXCEL_SHEET_TSEQ			13
#define EXCEL_SHEET_TCOND			14
#define EXCEL_SHEET_TC_ERR			15
#define EXCEL_SHEET_INFI			16
#define EXCEL_SHEET_MNTN			17

// Define specifiche del foglio Excel "Zone description"//
#define EXCEL_MAX_ROW_ZONE			50
#define EXCEL_COL_NAME_ZONE			2
#define EXCEL_COL_VIRT_ZONE			3
#define EXCEL_COL_BOTTOM_LEFT_X		4
#define EXCEL_COL_BOTTOM_LEFT_Y		5
#define EXCEL_COL_TOP_RIGHT_X		6
#define EXCEL_COL_TOP_RIGHT_Y		7
#define EXCEL_CONN_ZONES_1			8
#define EXCEL_MAX_CONN_ZONES		3
#define EXCEL_COL_CORRIDORS_1		EXCEL_CONN_ZONES_1 + EXCEL_MAX_CONN_ZONES
#define EXCEL_COL_CORR_X_OFFSET		1
#define EXCEL_COL_CORR_Y_OFFSET		2
#define EXCEL_COL_CORR_ZONE_OFFSET	3
#define EXCEL_COL_CORR_ANG_OFFSET	4
#define EXCEL_MAX_CORRIDORS			EXCEL_MAX_CONN_ZONES
#define EXCEL_COL_ALL_OBJT_1		EXCEL_COL_CORRIDORS_1 + (5*EXCEL_MAX_CORRIDORS) 
#define EXCEL_MAX_ALL_OBJT			10
#define EXCEL_COL_SUBZONES_1		EXCEL_COL_ALL_OBJT_1 + EXCEL_MAX_ALL_OBJT
#define EXCEL_MAX_SUBZONES			14
#define EXCEL_COL_MIN_VX			EXCEL_COL_SUBZONES_1 + EXCEL_MAX_SUBZONES + 1
#define EXCEL_COL_MAX_VX			EXCEL_COL_MIN_VX + 1
#define EXCEL_COL_MIN_VY			EXCEL_COL_MAX_VX + 1
#define EXCEL_COL_MAX_VY			EXCEL_COL_MIN_VY + 1
#define EXCEL_MAX_COL_ZONE			EXCEL_COL_MAX_VY

#define EXCEL_ROW_DATA_INIT_ZONE	3

//Define specifiche per il foglio Excel "Object Type"//
#define EXCEL_COL_NAME_OBJT			1
#define EXCEL_COL_DESCR_OBJT		2
#define EXCEL_COL_LENGHT_OBJT		3
#define EXCEL_COL_WEIGHT_OBJT		4
#define EXCEL_COL_LEG_SOURCE_1		5
#define EXCEL_MAX_LEG_SOURCE		6
#define EXCEL_COL_LEG_DEST_1		EXCEL_COL_LEG_SOURCE_1 + EXCEL_MAX_LEG_SOURCE
#define	EXCEL_MAX_LEG_DEST			5
#define EXCEL_COL_OBJT_ADD_1		EXCEL_COL_LEG_DEST_1 + EXCEL_MAX_LEG_DEST
#define EXCEL_MAX_OBJT_ADD			2
#define EXCEL_COL_LEG_MAST_1		EXCEL_COL_OBJT_ADD_1 + EXCEL_MAX_OBJT_ADD
#define EXCEL_MAX_LEG_MAST			3
#define EXCEL_COL_SYMBOL_OBJT		EXCEL_COL_LEG_MAST_1 + EXCEL_MAX_LEG_MAST
#define EXCEL_COL_SHNAME_OBJT		EXCEL_COL_SYMBOL_OBJT + 1
#define EXCEL_COL_GEN_TYPE			EXCEL_COL_SHNAME_OBJT + 1

#define EXCEL_ROW_DATA_INIT_OBJT	3

// Define specifiche del foglio Excel "Virtual coordinate zone"//
#define EXCEL_MAX_ROW_CELL			1500
#define EXCEL_COL_ZONE_NUM			1
#define EXCEL_COL_VIRT_X			2
#define EXCEL_COL_VIRT_Y			3
#define EXCEL_COL_PHYS_X			4
#define EXCEL_COL_PHYS_Y			5
#define EXCEL_COL_PHYS_Z			6 //Colonna al momento inutilizzata//
#define EXCEL_ALL_ANGLE_1			7
#define EXCEL_ALL_ANGLE_2			8
#define EXCEL_ALL_ROT				9
#define EXCEL_COL_CELL_TYPE			10

#define EXCEL_ROW_COORD_TYPE		1
#define EXCEL_COL_COORD_TYPE		4
#define EXCEL_ROW_DATA_INIT_CELL	3

// Define specifiche del foglio Excel "Virtual coordinate zone"//
#define EXCEL_MAX_ROW_PATH			1000
#define EXCEL_COL_SOURCE_PATH		1
#define EXCEL_COL_DEST_PATH			2
#define EXCEL_COL_STEP_PATH			3

#define EXCEL_ROW_DATA_INIT_PATH	3

//Define specifiche per il foglio Excel "Objects".//
#define EXCEL_MAX_ROW_OBJ			1000
#define EXCEL_COL_NAME_OBJ			1
#define EXCEL_COL_TYPE_OBJ			2
#define EXCEL_COL_STAT_OBJ			3
#define EXCEL_COL_PHYX_OBJ			4
#define EXCEL_COL_PHYY_OBJ			5
#define EXCEL_COL_PHYZ_OBJ			6

#define EXCEL_ROW_DATA_INIT_OBJ		3

//Define specifiche per il foglio Excel "Micro-op".//
#define EXCEL_MAX_ROW_MICR			100
#define EXCEL_COL_NAME_MICR			1
#define EXCEL_COL_DESC_MICR			2

#define EXCEL_ROW_DATA_INIT_MICR	3

//Define specifiche per il foglio Excel "Macro-op".//
#define EXCEL_MAX_ROW_MACR			1000
#define MACR_MAX_NUMBER				30
#define EXCEL_COL_NAME_MACR			1
#define EXCEL_COL_OBJT_MACR			2

#define EXCEL_ROW_DATA_INIT_MACR	3

//Define per il foglio Excel "Op-Seq"//
#define EXCEL_COL_MACROP_OSEQ		2
#define EXCEL_COL_OBJT_OSEQ			3
#define EXCEL_COL_ZONENAME_OSEQ		4
#define EXCEL_COL_CELLTYPE_OSEQ		5
#define EXCEL_COL_MICRNUM_OSEQ		6
#define EXCEL_COL_MICROOP_OSEQ		7	
#define EXCEL_COL_MICROCODE_OSEQ	8
#define EXCEL_COL_MICROPAR1_OSEQ	9
#define EXCEL_COL_MICROPAR2_OSEQ	10
//#define EXCEL_COL_MICROPAR3_OSEQ	10
//#define EXCEL_COL_MICROPAR4_OSEQ	11

#define EXCEL_ROW_DATA_INIT_OSEQ	3
#define	EXCEL_ROW_BOUND_OSEQ		1500

#define COMMAND_OPEN				1
#define	COMMAND_CLOSE				0

//Define per il foglio Excel "Phases"//
#define EXCEL_COL_PHAS_NUM			1
#define EXCEL_COL_PHAS_TCID			2
#define EXCEL_COL_PHAS_OBJE			3
#define EXCEL_COL_PHAS_SVC_X		4
#define EXCEL_COL_PHAS_SVC_Y		5
#define EXCEL_COL_PHAS_DVC_X		6
#define EXCEL_COL_PHAS_DVC_Y		7
#define EXCEL_COL_PHAS_OBJT			8
#define EXCEL_COL_PHAS_SIPP			9
#define EXCEL_COL_PHAS_NOTE			10

#define EXCEL_ROW_DATA_INIT_PHAS	3
#define	EXCEL_ROW_BOUND_PHAS		EXCEL_ROW_DATA_INIT_PHAS + 1000

//Define per il foglio Excel "Technological cycles"//
#define EXCEL_COL_ID_TC				1
#define EXCEL_COL_DESCR_TC			2
#define EXCEL_COL_ALL_SOUR_TC		3
#define EXCEL_COL_FIRST_ALL_DEST_TC	4
#define EXCEL_COL_FIRST_ALL_OBJT_TC	11
#define EXCEL_COL_FIRST_COND_TC		EXCEL_COL_FIRST_ALL_OBJT_TC + 10
#define EXCEL_COL_MARKING_TC		EXCEL_COL_FIRST_COND_TC + 50
#define EXCEL_COL_SD_ENABLED		EXCEL_COL_MARKING_TC + 1
#define EXCEL_COL_OBJ_ENABLED		EXCEL_COL_SD_ENABLED + 1
#define EXCEL_COL_COND_ENABLED		EXCEL_COL_OBJ_ENABLED + 1
#define EXCEL_COL_HECA_INT			EXCEL_COL_COND_ENABLED + 1
#define EXCEL_COL_FFDS_INT			EXCEL_COL_HECA_INT + 1
#define EXCEL_COL_CONT_IDX			EXCEL_COL_FFDS_INT + 1

#define EXCEL_ROW_DATA_INIT_TC		4
#define	EXCEL_ROW_BOUND_TC			EXCEL_ROW_DATA_INIT_TC + 1000

//Define per il foglio Excel "Infi90 Start Data"//
#define EXCEL_COL_NAME_INFI			2
#define EXCEL_COL_ICI_INFI			3
#define EXCEL_COL_LOOP_INFI			4
#define EXCEL_COL_PCU_CH_A_INFI		5
#define EXCEL_COL_PCU_CH_B_INFI		6
#define EXCEL_COL_MODULE_INFI		7
#define EXCEL_COL_BLOCK_INFI		8
#define EXCEL_COL_DATA_INFI			9
#define EXCEL_COL_SHEET_INFI		10
#define EXCEL_COL_ROW_INFI			11
#define EXCEL_COL_COL_INFI			12

#define EXCEL_ROW_DATA_INIT_INFI	4
#define EXCEL_MAX_ROWS_INFI			EXCEL_ROW_DATA_INIT_SC + 250

//Define per il foglio Excel "Technological cycles Sequences"//
#define EXCEL_COL_TCID_TCS			1
#define EXCEL_COL_OPSEQ_TCS			2
#define EXCEL_COL_OPTYPE_TCS		3
#define EXCEL_COL_MAST_TCS			4
#define EXCEL_COL_PAR1_TCS			5
#define EXCEL_COL_PAR2_TCS			6
#define EXCEL_COL_COND_TYPE_TCS		7
#define EXCEL_COL_COND_MAST_TCS		8
#define EXCEL_COL_COND_VX_TCS		9
#define EXCEL_COL_COND_VY_TCS		10
#define EXCEL_COL_COND_OBJT_TCS		11
#define EXCEL_COL_COND_ACTION_TCS	12
#define EXCEL_COL_COND_GOTO_TCS		13
#define EXCEL_COL_COND_TCID_TCS		14
#define EXCEL_COL_COND_FROP_TCS		15
#define EXCEL_COL_COND_TOOP_TCS		16
#define EXCEL_COL_DESCR_TCS			17

#define EXCEL_ROW_DATA_INIT_TCS		5
#define	EXCEL_ROW_BOUND_TCS			EXCEL_ROW_DATA_INIT_TCS + 420

//Define per il foglio Excel "Start Conditions"//
#define EXCEL_COL_IDX_SC			1
#define EXCEL_COL_DESCR_SC			2
#define EXCEL_COL_REQ_SC			3
#define EXCEL_COL_CHECKTYPE_SC		4
#define EXCEL_COL_TAGNAME_SC		5
#define EXCEL_COL_VALUE_SC			6

#define EXCEL_ROW_DATA_INIT_SC		5
#define	EXCEL_ROW_BOUND_SC			EXCEL_ROW_DATA_INIT_SC + 500

//Define per il foglio Excel "Maintenance data"//
#define EXCEL_COL_IDX_MNTN			1
#define EXCEL_COL_DESCR_MNTN		2
#define EXCEL_COL_MOV_IDX_MNTN		3

#define EXCEL_ROW_DATA_INIT_MNTN	4
#define	EXCEL_ROW_BOUND_MNTN		EXCEL_ROW_DATA_INIT_MNTN + 100

//Define per il foglio Excel "Maintenance data"//
#define EXCEL_COL_IDX_TC_ERR		1
#define EXCEL_COL_DESCR_TC_ERR		2

#define EXCEL_ROW_DATA_INIT_TC_ERR	4
#define	EXCEL_ROW_BOUND_TC_ERR		EXCEL_ROW_DATA_INIT_TC_ERR + TC_ERR_REC


// Define specifiche per i message box e per il file di log//
#define MSGBOX_TITLE				_T("Builder")
#define MSGBOX_ERR_COL_INSERT_ZONE	_T("Excel data acquisition: error in row %d, column %d, worksheet %s.")
#define MSGBOX_ERR_COL_INSERT_CELL	_T("Excel data acquisition: error in row %d, column %d, worksheet %s, zone IDX %d.") 
#define MSGBOX_ERR_COL_INSERT_OBJT	_T("Excel data acquisition: error in row %d, column %d, worksheet %s.")
#define MSGBOX_WRN_COL_INSERT_OBJT	_T("Excel data acquisition: warning data missing in row %d, column %d, worksheet %s.")
#define MSGBOX_ERR_COL_INSERT_OBJE	_T("Excel data acquisition: error in row %d, column %d, worksheet %s.")
#define MSGBOX_WRN_COL_INSERT_OBJE	_T("Excel data acquisition: warning data missing in row %d, column %d, worksheet %s.")
#define MSGBOX_ERR_COL_INSERT_OSEQ	_T("Excel data acquisition: error in row %d, column %d, worksheet %s.")
#define MSGBOX_WRN_COL_INSERT_OSEQ	_T("Excel data acquisition: warning data missing in row %d, column %d, worksheet %s.")

//Define specifiche per le funzioni di controllo dei dati in input.//
#define MAX_PHYS_COORD_X			10000
#define MIN_PHYS_COORD_X			0
#define MAX_PHYS_COORD_Y			10000
#define MIN_PHYS_COORD_Y			0
#define MAX_PHYS_COORD_Z			10000
#define MIN_PHYS_COORD_Z			0
#define MAX_VIRT_COORD_X			10000
#define MIN_VIRT_COORD_X			0
#define MAX_VIRT_COORD_Y			10000
#define MIN_VIRT_COORD_Y			0
#define MAX_ROT_ANGLE				315
#define MIN_ROT_ANGLE				0

//Define tipi messaggi//
#define TNT_BUILD_START				1
#define TNT_BUILD_STEP				2
#define TNT_BUILD_END				3

//Dichiarazioni delle funzioni (esportabili) del builder.//
TNTBUILDER_API int AcquireZone(CXlsObj *excelObj, int *zoneCount, HWND hWnd);
TNTBUILDER_API int AcquireSubZones(CXlsObj *excelObj);
TNTBUILDER_API int AcquireCell(CXlsObj *excelObj, ZONENAME zone, bool keepObjects, HWND hWnd);
TNTBUILDER_API int AcquireAllCells(CXlsObj *excelObj, bool keepObjects, HWND hWnd);
TNTBUILDER_API int AcquireObjT(CXlsObj *excelObj, HWND hWnd);
TNTBUILDER_API int AcquireZoneAllObjT(CXlsObj *excelObj, ZONENAME zoneName);
TNTBUILDER_API int AcquireLegalPaths(CXlsObj *excelObj, ZONENAME zoneName);
TNTBUILDER_API int AcquireObj(CXlsObj *excelObj, int *objCount, HWND hWnd);
TNTBUILDER_API int AcquireMicr(CXlsObj *excelObj, int *micrCount, HWND hWnd);
TNTBUILDER_API int AcquireMacr(CXlsObj *excelObj, int *macrCount, HWND hWnd);
TNTBUILDER_API int AcquireOseq(CXlsObj *excelObj, HWND hWnd);
TNTBUILDER_API int AcquirePhas(CXlsObj *excelObj, int sheet, HWND hWnd);
TNTBUILDER_API int AcquireTecc(CXlsObj *excelObj, HWND hWnd);
TNTBUILDER_API int AcquireTCSeq(CXlsObj *excelObj, HWND hWnd);
TNTBUILDER_API int AcquireTCStartCond(CXlsObj *excelObj, HWND hWnd);
TNTBUILDER_API int AcquireInfi90Data(CXlsObj *excelObj, DWORD opStation, HWND hWnd, bool sendToA, bool sendToB);
TNTBUILDER_API int AcquireMaintData(CXlsObj *excelObj, int excelInstance, DWORD opStation, HWND hWnd);
TNTBUILDER_API int AcquireTCErr(CXlsObj *excelObj, int excelInstance, DWORD opStation, HWND hWnd);
TNTBUILDER_API int LogFileWrite(TCHAR cmd[4], TCHAR *Comment);
TNTBUILDER_API int ActivateLog(void);
TNTBUILDER_API int DeactivateLog(void);
TNTBUILDER_API int SetLogPath(TCHAR *path);
TNTBUILDER_API int ActivateApmsServer(TCHAR *serverName, LPDWORD clientNum, bool mode);
TNTBUILDER_API int DeactivateApmsServer();
TNTBUILDER_API int F_ZONE_Check(void);
TNTBUILDER_API int F_OBJT_Check(void);
TNTBUILDER_API int GetWrnFlag(BOOL *flag);
TNTBUILDER_API RETSTAT InitZone(t_zone *zone);
TNTBUILDER_API RETSTAT InitCell(t_cell *cell);
TNTBUILDER_API RETSTAT InitObjT(t_obj_type *objt);
TNTBUILDER_API RETSTAT InitObj(t_obj *obj);
TNTBUILDER_API RETSTAT InitMacr(t_macro_cmd *macr);
TNTBUILDER_API RETSTAT InitOseq(t_ope_seq *oseq);
TNTBUILDER_API RETSTAT InitMice(micro_cmd_exe *mice);
TNTBUILDER_API RETSTAT InitDynp(dynamic_struc *dynp);
TNTBUILDER_API RETSTAT InitPhas(phas_struc *phas);
TNTBUILDER_API RETSTAT InitTechCyc(t_teccyc *tc);
TNTBUILDER_API RETSTAT InitCamp(t_camp *camp);
TNTBUILDER_API RETSTAT InitTCSeq(tc_seq *seq);
TNTBUILDER_API RETSTAT InitTCStartCond(tcStartCond *tcSc);
TNTBUILDER_API RETSTAT InitInfiBlock(t_infiBlock *block);
TNTBUILDER_API RETSTAT InitTCErr(t_tcErr *tcErr);
TNTBUILDER_API BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
TNTBUILDER_API RETSTAT InitF_CEFile(int fileNum);
TNTBUILDER_API RETSTAT InitF_OBJE(void);
TNTBUILDER_API RETSTAT InitF_TCER(void);
//Dichiarazioni delle funzioni (non esportabili) del builder.//
int RangeSplit(TCHAR *strRange, float *r1, float *r2);

#endif